import {getBanners,reqRecommendList, reqNewSongs,reqRecommendMv,reqHighQualityPlayList} from '@/api'

const state = {
    banners:[],
    recommendList:[],
    newSongs:[],
    mvList:[],
    highQualityPlayList:{}
}


const mutations = {
    BANNERS(state, banners){
        state.banners = banners
    },
    RECOMMENDLIST(state, recommendList){
        state.recommendList = recommendList
    },
    NEWSONGS(state, newSongs){
        state.newSongs = newSongs
    },
    MVLIST(state, mvList){
        state.mvList = mvList
    },
    HIGHQUALITYPLAYLIST(state, highQualityPlayList){
        state.highQualityPlayList = highQualityPlayList
    },
    APPENDHIGHQUALITYPLAYLIST(state, highQualityPlayList){
        state.highQualityPlayList.playlists.push(...highQualityPlayList.playlists)
        state.highQualityPlayList.lasttime = highQualityPlayList.lasttime
    },
}

const actions = {
    async banners({commit}){
        let result = await getBanners()
        if(result.code === 200){
            commit("BANNERS", result.banners)
        }
    },
    async recommendList({commit}){
        let result = await reqRecommendList()
        if(result.code == 200){
            commit("RECOMMENDLIST", result.recommend)
        }
    },
    async newSongs({commit}){
        let result = await reqNewSongs()
        if(result.code == 200){
            commit("NEWSONGS", result.result)
        }
    },
    async mvList({commit}){
        let result = await reqRecommendMv()
        if(result.code == 200){
            commit("MVLIST", result.result)
        }
    },
    async highQualityPlayList({commit}, before=0){
        let data
        if(before == 0){
            data = {limit:21}
            let result = await reqHighQualityPlayList(data)
            if(result.code == 200){
                commit("HIGHQUALITYPLAYLIST", result)
            }
        }else{
            data = {before, limit:20}
            let result = await reqHighQualityPlayList(data)
            if(result.code == 200){
                commit("APPENDHIGHQUALITYPLAYLIST", result)
            }
        }

    },
}

const getter = {}

export default  {
    state,
    mutations,
    actions,
    getter
}